package com.leejxx.health.controller;

import com.leejxx.health.common.MessageConst;
import com.leejxx.health.entity.PageResult;
import com.leejxx.health.entity.QueryPageBean;
import com.leejxx.health.entity.Result;
import com.leejxx.health.pojo.Permission;
import com.leejxx.health.service.PermissionService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author LeeJx
 * @ClassName PermissionController
 * @Description TODO
 * @date 2021/1/11 8:56
 * @Version 1.0
 */
@RestController
@Slf4j
@RequestMapping("/permission")
public class PermissionController {
    @DubboReference
    private PermissionService permissionService;

    @RequestMapping("/findByPage")
    public Result findByPage(@RequestBody QueryPageBean queryPageBean) {
        log.info("[权限管理-分页查询]data:{}", queryPageBean);
        PageResult pageResult = permissionService.findByPage(queryPageBean);
        log.info("[权限管理-分页查询成功]data:{}", pageResult);
        return new Result(true, MessageConst.ACTION_SUCCESS, pageResult);
    }

    @RequestMapping("/add")
    public Result add(@RequestBody Permission permission) {
        log.info("[权限管理-新增权限]data:{}", permission);
        permissionService.add(permission);
        log.info("[权限管理-新增权限成功]");
        return new Result(true, MessageConst.ACTION_SUCCESS);
    }

    @RequestMapping("/findById")
    public Result findById(Integer permissionId) {
        log.info("[权限管理-编辑回显]data:{}", permissionId);
        Permission permission = permissionService.findById(permissionId);
        log.info("[权限管理-编辑回显成功]data:{}", permission);
        return new Result(true, MessageConst.ACTION_SUCCESS, permission);
    }

    @RequestMapping("/edit")
    public Result edit(@RequestBody Permission permission) {
        log.info("[权限管理-编辑权限]data:{}", permission);
        permissionService.edit(permission);
        log.info("[权限管理-编辑权限成功]");
        return new Result(true, MessageConst.ACTION_SUCCESS);
    }

    @RequestMapping("/delete")
    public Result delete(Integer permissionId) {
        log.info("[权限管理-删除权限]data:{}", permissionId);
        permissionService.delete(permissionId);
        log.info("[权限管理-删除权限成功]");
        return new Result(true, MessageConst.ACTION_SUCCESS);
    }
}
